package com.tjvib.util.retrofit;

import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * 使用：RequestBody requestBody = new JsonParams().put(“name”, “zhangsan”).create();
 */
public class JsonParams {
    JSONObject params = new JSONObject();

    public JsonParams put(String key, Object value) {
        try {
            params.put(key, value);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return this;
    }

    public RequestBody create() {
        return RequestBody.create(params.toString(), MediaType.parse("application/json"));
    }
}

